<?
	include_once("cmsConfig.php");
	
	define("CMS_ADD_QUICK_ADD_FOLDER",1);
	define("CMS_ADD_QUICK_ADD_GO",2);
	define("CMS_ADD_QUICK_ADD_WITH_PERMISSIONS_GO",3);
	define("CMS_ADD_FILES_AND_FOLDERS",4);
	
	
	function displayFilesFoldersQuickAdd(&$formDescription, $label, &$authInfo, $gid, $optionDictionary, &$db) {
		if (addFormAuth($authInfo, $formDescription, null, $db)) {
			$parent = extractNumberWithKeyFromArray("parent", $_REQUEST);
			?>
			  <table id="cms_folderquickadd" class="cms_folderquickadd" border="0" align="right" cellpadding="0" cellspacing="0">
			    <tr>
				  <td valign="middle"><?= $label?>: &nbsp;</td>
				  <td valign="middle">
			<form action="<?= $_SERVER["PHP_SELF"]; ?>" method="post">
			  <input type="hidden" name="formId" value="<?= $formDescription->formid; ?>">
			  <?
			  if (!is_null($optionDictionary) && is_array($optionDictionary)) {
				  foreach ($optionDictionary as $key=>$value) {
					  echo "<input type='hidden' name='".$key."' value='".$value."'>\n";
				  }
			  }
			  ?>
			  <input type="hidden" name="fileNo" value="2" />
			  <input type="hidden" name="processFormData" value="YES" />
			  <input type="hidden" name="active" value="1" />
			  <input type="hidden" name="author" value="1">
			  <?
			  $db->executeQuery("SELECT sourcequery FROM formelement WHERE 
				  					elementid='".$formDescription->documenttypecode."'");
			  if ($elementDoc = $db->nextRow()) {
				  $db->executeQuery($elementDoc[0]);
				  if ($documenttypeDoc = $db->nextRow()) {
					  ?>
					  <input type="hidden" name="documenttypecode" value="<?= $documenttypeDoc[0]; ?>">
					  <?
				  }
			  }
			  if ($parent) {
				  ?>
				  <input type="hidden" name="categorycode" value="<?= $parent; ?>">
				  <?
			  }
			  ?>
				    <input name="title" type="text" style="width: 150px" />
					<?
					if (CMS_ENABLE_USER_PERMISSIONS ) {
						if ($authInfo->usertype != CMS_USERTYPE_SU ) {
							$groups = groupsForUserId($authInfo->uid, $db);
							$q = "SELECT gid, groupname FROM grouplist WHERE gid IN (" . implode(',', $groups ) . ") ORDER BY gid";
						}
						else {
							$q = "SELECT gid, groupname FROM grouplist  ORDER BY gid";			
						}
						echo "<select name='gid' >\n";
						//get the groups here....
						$db->executeQuery($q);
						echo "<option value='0'>-</option>\n";
						while ($row = $db->nextObject()) {
							if ($row->gid == $formDescription->gid ) {
								$selected = "selected='yes'"; 
							}
							else {
								$selected = "";
							}
							echo "<option ".$selected." value='".$row->gid."'>".$row->groupname."</option>\n";
						}
						echo "</select>\n";
					}
					?>
				  </td>
				  <td width="56" valign="middle" ><input type="image" name="imageField" src="/cms/images/button_go.gif" /></td>
				  </form>
				  <td>
				    <?
					if ($parent) {
						if ( !isset($addInputFields) || !$addInputFields){
							$addInputFields = "<input type='hidden' name='fileNo' value='".FILES_AND_IMAGES_ADD."' />\n";
							$addInputFields .= "<input type='hidden' name='formId' value='".$formDescription->formid."' />\n";
							$addInputFields .= "<input type='hidden' name='parent' value='".$parent."'>\n";
						}
						$self = $_SERVER['PHP_SELF'];
						echo "<form method='post' action='".$self."'>\n";
						echo $addInputFields;
						echo "  <input type='image' src='/cms/images/cnt_add_new_record.gif' />\n";
						echo "</form>\n";
						echo "<a href='/cms/html/index.php?fileNo=2&documentCode=".$parent."' >Edit Folder</a>\n";
						echo "&nbsp;&nbsp;";
						echo "<a href='/cms/html/index.php?fileNo=4&documentCode=".$parent."' >Delete Folder</a>\n";
					}
					?>
				  </td>
				</tr>
			  </table>
			<?
		}
	}
	
	function displayFolderQuickAdd(&$formDescription, $label, &$authInfo, $gid, $optionDictionary, &$db){

		if (addFormAuth($authInfo, $formDescription, null, $db)) {
?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" >	
	
	<input type="hidden" name="formId" value="<?= $formDescription->formid ?>" />
<?
	if (!is_null($optionDictionary) && is_array($optionDictionary)) {
		foreach ($optionDictionary as $key => $value ) {
			print <<< EOD
<input type="hidden" value="$value" name="$key" />			
EOD;
		}
	}
?>

	<input type="hidden" name="fileNo" value="2" />
	<input type="hidden" name="processFormData" value="YES" />
	<input type="hidden" name="active" value="1" />
	
  <table id="cms_folderquickadd" class="cms_folderquickadd" border="0" align="right" cellpadding="0" cellspacing="0">
    <tr>
		<td valign="middle"><?= $label?>: &nbsp;</td>
        <td valign="middle"><input name="title" type="text" style="width: 150px" />
          <?

	if (CMS_ENABLE_USER_PERMISSIONS ) {
		if ($authInfo->usertype != CMS_USERTYPE_SU ) {
			$groups = groupsForUserId($authInfo->uid, $db);
			$q = "SELECT gid, groupname FROM grouplist WHERE gid IN (" . implode(',', $groups ) . ") ORDER BY gid";
		} else {
			$q = "SELECT gid, groupname FROM grouplist  ORDER BY gid";			
		}
		echo "<select name=\"gid\" >\n";
		//get the groups here....
		$db->executeQuery($q);
		echo "<option  value=\"" . 0 . "\">-</option>\n";
		while ($row = $db->nextObject()) {
			if ($row->gid == $formDescription->gid ) {
				$selected = "selected=\"yes\""; 
			} else { 
				$selected = "";
			}
			echo "<option ". $selected ." value=\"" . $row->gid . "\">" . $row->groupname . "</option>\n";
		}
	
		echo "</select>\n";
	}


?></td>
        <td width="56" valign="middle" ><input type="image" name="imageField" src="/cms/images/button_go.gif" /></td>
    </tr>
  </table>
</form>
<?

		}
	}
	
	
	function displayGoAdd(&$formDescription, &$authInfo, $gid, $optionDictionary, &$db) {
		echo "DEPRECATED";
		die("DEPRECATED");
	}		
?>